
library(survival)
library(Amelia)
library(AER)
library(DataCombine)
library(stargazer)
library(MatchIt)
library(interflex)

setwd("")

surv.df <- read.csv("Morse_FATF_CrimTF.csv", header=TRUE)

###############################
###Appendix Code
###############################

#####################
##Appendix F: Multiple Imputation
#####################

vars <- c("ccode", "period", "periodnext",
          "crimtfnew", "listedc", "log.liabc",
          "fatfc", "crimtfindc", "diffusion2c",
          "risklistingc", "usallyc", "log.creditkc",
          "log.gdppckc", "terrorismc", "newpolityc")
temp <- surv.df[vars]
a.out <- amelia(x = temp, cs = "ccode", ts = "period")
summary(a.out)

a.out.more <- amelia(x=temp, m=10, cs = "ccode", ts = "period")
a.out.more <- ameliabind(a.out, a.out.more)
summary(a.out.more)

df <- a.out.more$imputations[[1]]
summary(df)

imp1 <- coxph(Surv(period, periodnext, crimtfnew) ~
                listedc+
                fatfc+
                crimtfindc+
                diffusion2c+
                risklistingc+
                usallyc+
                usallyc:log(periodnext)+
                cluster(ccode),
              robust=TRUE, data=df)

imp2 <- coxph(Surv(period, periodnext, crimtfnew) ~
                listedc*log.liabc+
                fatfc+
                crimtfindc+
                diffusion2c+
                risklistingc+
                usallyc+
                usallyc:log(periodnext)+
                log.creditkc+
                log.gdppckc+
                cluster(ccode),
              robust=TRUE, data=df)

imp3 <- coxph(Surv(period, periodnext, crimtfnew) ~
                listedc*log.liabc+
                fatfc+
                crimtfindc+
                diffusion2c+
                risklistingc+
                usallyc+
                usallyc:log(periodnext)+
                log.creditkc+
                log.gdppckc+
                terrorismc+
                cluster(ccode),
              robust=TRUE, data=df)

imp4 <- coxph(Surv(period, periodnext, crimtfnew) ~
                listedc*log.liabc+
                fatfc+
                crimtfindc+
                diffusion2c+
                risklistingc+
                usallyc+
                usallyc:log(periodnext)+
                log.creditkc+
                log.gdppckc+
                terrorismc+
                newpolityc+
                cluster(ccode),
              robust=TRUE, data=df)

stargazer(imp1, imp2, imp3, imp4,
          apply.coef=exp,
          t.auto=F,
          p.auto=F,
          title="Effect of Non-Complier List on Criminalization (Imputed Data)",
          align=TRUE,
          covariate.labels=c("Listing",
                             "Market Integration",
                             "FATF Member",
                             "Previous Terrorist Fin Law", 
                             "Diffusion",
                             "Eligible for Listing",
                             "US Ally",
                             "Private Sector Credit", 
                             "Capacity",
                             "Terrorism", 
                             "Democracy",
                             "Listing * Market Integration"),
          column.sep.width="2pt")

###################
###Appendix G: Models in Table 1 without log-time interaction
###################

cft.cox1 <- coxph(Surv(period, periodnext, crimtfnew) ~
                    listedc+
                    fatfc+
                    crimtfindc+
                    diffusion2c+
                    risklistingc+
                    usallyc+
                    cluster(ccode),
                  robust=TRUE, data=surv.df)
summary(cft.cox1)

cft.cox2 <- coxph(Surv(period, periodnext, crimtfnew) ~
                    listedc*log.liabc+
                    fatfc+
                    crimtfindc+
                    diffusion2c+
                    risklistingc+
                    usallyc+
                    log.creditkc+
                    log.gdppckc+
                    cluster(ccode),
                  robust=TRUE, data=surv.df)
summary(cft.cox2)

cft.cox3 <- coxph(Surv(period, periodnext, crimtfnew) ~
                    listedc*log.liabc+
                    fatfc+
                    crimtfindc+
                    diffusion2c+
                    risklistingc+
                    usallyc+
                    log.creditkc+
                    log.gdppckc+
                    terrorismc+
                    cluster(ccode),
                  robust=TRUE, data=surv.df)
summary(cft.cox3)

cft.cox4 <- coxph(Surv(period, periodnext, crimtfnew) ~
                    listedc*log.liabc+
                    fatfc+
                    crimtfindc+
                    diffusion2c+
                    risklistingc+
                    usallyc+
                    log.creditkc+
                    log.gdppckc+
                    terrorismc+
                    newpolityc+
                    cluster(ccode),
                  robust=TRUE, data=surv.df)
summary(cft.cox4)

stargazer(cft.cox1, cft.cox2, cft.cox3, cft.cox4,
          apply.coef=exp,
          t.auto=F,
          p.auto=F,
          title="Effect of Non-Complier List on Criminalization",
          align=TRUE,
          covariate.labels=c("Listing",
                             "Market Integration",
                             "FATF Member",
                             "Previous Terrorist Fin Law", 
                             "Diffusion",
                             "Eligible for Listing",
                             "US Ally",
                             "Private Sector Credit", 
                             "Capacity",
                             "Terrorism", 
                             "Democracy",
                             "Listing * Market Integration"),
          column.sep.width="2pt")


##########################
##Appendix H: Hainmueller et al. interaction tests
###########################

temp <- surv.df[!is.na(surv.df$log.creditkc) &
                  !is.na(surv.df$log.gdppckc) &
                  !is.na(surv.df$log.liabc) &
                  !is.na(surv.df$terrorismc) &
                  !is.na(surv.df$newpolityc),]
length(unique(temp[temp$listed==1,]$ccode))##30
length(unique(temp$ccode))##87

###Approach 1: Binning Estimator

inter.binning(Y="crimtfnew", D="listedc",
              X="log.liabc",
              Z=c("fatfc", "crimtfindc",
                  "diffusion2c", "risklistingc",
                  "usallyc", "log.creditkc",
                  "log.gdppckc", "terrorismc",
                  "newpolityc"),
              data=temp,
              nbins=3,
              vartype = "cluster",
              cl="ccode",
              Ylabel="Crim TF",
              Dlabel="List",
              Xlabel="Market Integration")

##Approach #2: Kernel Estimator
inter.kernel(Y="crimtfnew", D="listedc",
             X="log.liabc",
             Z=c("fatfc", "crimtfindc",
                 "diffusion2c", "risklistingc",
                 "usallyc", "log.creditkc",
                 "log.gdppckc", "terrorismc",
                 "newpolityc"),
             data=temp,
             cl="ccode",
             Ylabel="Crim TF",
             Dlabel="List",
             Xlabel="Market Integration",
             nboots=50,
             parallel=FALSE)


###############################
###Appendix I: Listing as an Ordinal Variable
###############################
surv.df$listlevel <- factor(surv.df$listlevel,
                            levels=c(0, 1, 2, 3),
                            ordered=TRUE)
surv.df$listlevel[1:5]
table(surv.df$listlevel)

cft.cox1 <- coxph(Surv(period, periodnext, crimtfnew) ~
                    listlevel+
                    fatfc+
                    crimtfindc+
                    diffusion2c+
                    risklistingc+
                    usallyc+
                    usallyc:log(periodnext)+
                    cluster(ccode),
                  robust=TRUE, data=surv.df)
summary(cft.cox1)

cft.cox4 <- coxph(Surv(period, periodnext, crimtfnew) ~
                    listlevel*log.liabc+
                    fatfc+
                    crimtfindc+
                    diffusion2c+
                    risklistingc+
                    usallyc+
                    usallyc:log(periodnext)+
                    log.creditkc+
                    log.gdppckc+
                    terrorismc+
                    newpolityc+
                    cluster(ccode),
                  robust=TRUE, data=surv.df)
summary(cft.cox4)

stargazer(cft.cox1, cft.cox4,
          apply.coef=exp,
          t.auto=F,
          p.auto=F)

#################################
##Appendix: Balance Statistics for Matching
###############################

surv.df2 <- surv.df
surv.df2 <- surv.df2[surv.df2$fatf==0,]
surv.df2 <- surv.df2[surv.df2$period==1,]

vars <- c("listed", "listedc", "period", "periodnext",
          "log.liabc", "crimtfindc", "diffusion2c",
          "risklistingc", "usallyc", "log.creditkc",
          "log.gdppckc", "newpolityc", "terrorismc",
          "ccode", "log.aidc")

surv.df2 <- surv.df2[vars]
surv.df2 <- surv.df2[complete.cases(surv.df2),]

m.out1 <- matchit(listed ~ 
                    diffusion2c+
                    usallyc+
                    log.creditkc+
                    log.gdppckc+
                    newpolityc+
                    terrorismc,
                  data = surv.df2, method = "nearest")
x <- summary(m.out1)

x$sum.all[1]
x$sum.all[2]
x$sum.all[4]
x$sum.matched[1]
x$sum.matched[2]
x$sum.matched[4]

##################################
###Appendix - Listing and Cross-Border Liabilities
###Trade Balance Substitution###
##################################
banks <- read.csv("Morse_FATF_banklending.csv", header=TRUE)

temp <- banks[!is.na(banks$lag.inflation) &
                !is.na(banks$lag.gdpgrowth) &
                !is.na(banks$lag.nettradek) &
                !is.na(banks$log.liab) &
                !is.na(banks$lag.listed) &
                !is.na(banks$lag.credit.gdp) &
                !is.na(banks$lag.debt.gdp),]

length(unique(temp[temp$lag.listed==1,]$ccode)) ##11
length(unique(temp$ccode)) ##57

###Note: to use the robust=T command, you need to have code from
###https://economictheoryblog.com/2016/08/07/robust-standard-errors-in-r-function/

fit1 <- lm(log.liab~lag.listed+
             lag.inflation+
             lag.gdpgrowth+
             lag.nettradek+
             lag.credit.gdp+
             lag.debt.gdp+
             factor(ccode-1),
           data=temp)
fit1a <- summary(fit1, robust=T)

fit2 <- lm(log.liab~lag.listed+
             lag.inflation+
             lag.gdpgrowth+
             lag.nettradek+
             lag.credit.gdp+
             lag.debt.gdp+
             time+time^2+time^3+
             factor(ccode-1),
           data=temp)
fit2a <- summary(fit2, robust=T)

temp2 <- temp[!is.na(temp$lag.m2) &
                !is.na(temp$lag.intratespread),]
length(unique(temp2[temp2$lag.listed==1,]$ccode)) ##9
length(unique(temp2$ccode)) ##35

fit3 <- lm(log.liab~lag.listed+
             lag.inflation+
             lag.gdpgrowth+
             lag.nettradek+
             lag.credit.gdp+
             lag.debt.gdp+
             lag.m2+
             lag.intratespread+
             factor(ccode-1),
           data=temp2)
fit3a <- summary(fit3, robust=T)

fit4 <- lm(log.liab~lag.listed+
             lag.inflation+
             lag.gdpgrowth+
             lag.nettradek+
             lag.credit.gdp+
             lag.debt.gdp+
             lag.m2+
             lag.intratespread+
             time+time^2+time^3+
             factor(ccode-1),
           data=temp2)
fit4a <- summary(fit4, robust=T)

stargazer(fit1, fit2, fit3, fit4,
          keep=c("lag.listed", 
                 "lag.inflation",
                 "lag.gdpgrowth", 
                 "lag.nettradek",
                 "lag.credit.gdp", 
                 "lag.debt.gdp",
                 "time",
                 "lag.m2",
                 "lag.intratespread"),
          title="The Effect of Listing on Bank-to-Bank Lending",
          align=TRUE,
          covariate.labels=c("Listing",
                             "Inflation",
                             "GDP Growth (Percent Change)",
                             "Balance of Trade",
                             "Credit-to-GDP Ratio",
                             "Debt-to-GDP Ratio",
                             "Time",
                             "Money Supply",
                             "Interest Rate Spread"),
          column.sep.width="0.1pt",
          keep.stat="n")

#######################################
####Appendix Table
####Robustness: Placebo Test for Cross-Border Bank Flows
######################################

banks2 <- read.csv("Morse_FATF_banklendingplacebo.csv", header=TRUE)

temp <- banks2[!is.na(banks2$lag.inflation) &
                 !is.na(banks2$lag.gdpgrowth) &
                 !is.na(banks2$lag.realexchangerate) &
                 !is.na(banks2$log.liab) &
                 !is.na(banks2$lag.fakelist) &
                 !is.na(banks2$lag.credit.gdp) &
                 !is.na(banks2$lag.debt.gdp),]

length(unique(temp[temp$lag.fakelist==1,]$ccode)) ##9
length(unique(temp$ccode)) ##50

fit1 <- lm(log.liab~lag.fakelist+
             lag.inflation+
             lag.gdpgrowth+
             lag.realexchangerate+
             lag.credit.gdp+
             lag.debt.gdp+
             factor(ccode-1),
           data=temp)
fit1a <- summary(fit1, robust=T)

fit2 <- lm(log.liab~lag.fakelist+
             lag.inflation+
             lag.gdpgrowth+
             lag.realexchangerate+
             lag.credit.gdp+
             lag.debt.gdp+
             time+time^2+time^3+
             factor(ccode-1),
           data=temp)
fit2a <- summary(fit2, robust=T)

temp2 <- temp[!is.na(temp$lag.m2) &
                !is.na(temp$lag.intratespread),]
length(unique(temp2[temp2$lag.fakelist==1,]$ccode)) ##5
length(unique(temp2$ccode)) ##14

fit3 <- lm(log.liab~lag.fakelist+
             lag.inflation+
             lag.gdpgrowth+
             lag.realexchangerate+
             lag.credit.gdp+
             lag.debt.gdp+
             lag.m2+
             lag.intratespread+
             factor(ccode-1),
           data=temp2)
fit3a <- summary(fit3, robust=T)

fit4 <- lm(log.liab~lag.fakelist+
             lag.inflation+
             lag.gdpgrowth+
             lag.realexchangerate+
             lag.credit.gdp+
             lag.debt.gdp+
             lag.m2+
             lag.intratespread+
             time+time^2+time^3+
             factor(ccode-1),
           data=temp2)
fit4a <- summary(fit4, robust=T)

stargazer(fit1, fit2, fit3, fit4,
          keep=c("lag.fakelist", 
                 "lag.inflation",
                 "lag.gdpgrowth", 
                 "lag.realexchangerate",
                 "lag.credit.gdp", 
                 "lag.debt.gdp",
                 "time",
                 "lag.m2",
                 "lag.intratespread"),
          title="Placebo Test: The Effect of Listing on Bank-to-Bank Lending",
          align=TRUE,
          covariate.labels=c("Fake Listing",
                             "Inflation",
                             "GDP Growth (Percent Change)",
                             "Real Exchange Rate",
                             "Credit-to-GDP Ratio",
                             "Debt-to-GDP Ratio",
                             "Time",
                             "Money Supply",
                             "Interest Rate Spread"),
          column.sep.width="0.1pt",
          keep.stat="n")

